<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Add User Information</title>
    <style>
    body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
    }

    h1 {
    text-align: center;
    color: #333;
    }

    form {
    max-width: 600px;
    margin: 20px auto;
    padding: 20px;
    background: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }

    label,
    input,
    select,
    textarea {
    display: block;
    margin-bottom: 15px;
    }

    input,
    select,
    textarea {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 5px;
    }

    button {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    }

    button:hover {
    background-color: #45a049;
    }
    </style>


</head>
<body>

<h1>Add Financial Information</h1>
<form action="/mananger/companyMessageAdd" method="post">
    <label for="companyName">公司名称</label>
    <input type="text" id="companyName" name="companyName" required><br>

    <label for="city">所在城市:</label>
    <input type="text" id="city" name="city" required><br>

    <label for="companyType">公司类型:</label>
    <select id="companyType" name="companyType"  required>
        <option value="" disabled selected>请选择</option>
        <option value="1">水费公司</option>
        <option value="2">燃气费公司</option>
        <option value="3">电费公司</option>
        <option value="4">通信公司</option>
    </select><br>

    <label for="companyCount">公司账户:</label>
    <input type="text" id="companyCount" name="companyCount" required><br>





    <button type="submit">Submit</button>
</form>
<script>
    document.getElementById('companyForm').addEventListener('submit', function(event) {
        event.preventDefault(); // 阻止表单默认提交行为

        // 使用 fetch 发起 POST 请求
        fetch('/mananger/companyMessageAdd', {
            method: 'POST',
            body: new FormData(document.getElementById('companyForm'))
        })
            .then(response => response.json()) // 假设后端返回 JSON 数据
            .then(result => {
                if (result.code === 0) {
                    layer.alert("更新成功", {icon: 6}, function () {
                        //关闭当前frame
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        // 可以对父窗口进行刷新
                        parent.location.reload();
                    });
                } else {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    parent.location.reload();
                    layer.msg("更新失败");
                }
            })
            .catch(error => {
                console.error('Error:', error);
                // 处理请求失败的情况
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.location.reload();
                layer.msg("更新失败");
            });
    });

</script>

</body>
</html>